﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using Brjnk.GpxExplorer.Data;
using Brjnk.GpxExplorer.ViewModel;
using Brjnk.MVVM;

namespace Brjnk.GpxExplorer.Workspace
{
    public class DataModel : DataItem
    {
        public DataModel()
        {
            this.Watcher = new DataChangeWatcher(this);

            DefineWatchedProperty("Waypoints", new ObservableCollectionEx<WaypointVM>());
            DefineWatchedProperty("Routes", new ObservableCollectionEx<RouteVM>());
            DefineWatchedProperty("Tracks", new ObservableCollectionEx<TrackVM>());
            DefineWatchedProperty("Photos", new Photos(Tracks, Watcher));

            AllObjects = new CompositeCollection();
            AllObjects.Add(new CollectionContainer() { Collection = Waypoints });
            AllObjects.Add(new CollectionContainer() { Collection = Routes });
            AllObjects.Add(new CollectionContainer() { Collection = Tracks });
        }

        public IEnumerable<DataItem> GetAllObjects()
        {
            return Waypoints.Cast<DataItem>().Concat(Routes).Concat(Tracks);
        }

        public ObservableCollectionEx<WaypointVM> Waypoints { get { return GetWatchedProperty<ObservableCollectionEx<WaypointVM>>("Waypoints"); } }

        public ObservableCollectionEx<RouteVM> Routes { get { return GetWatchedProperty<ObservableCollectionEx<RouteVM>>("Routes"); } }

        public ObservableCollectionEx<TrackVM> Tracks { get { return GetWatchedProperty<ObservableCollectionEx<TrackVM>>("Tracks"); } }

        public Photos Photos { get { return GetWatchedProperty<Photos>("Photos"); } }

        public CompositeCollection AllObjects { get; private set; }

        public DataChangeWatcher Watcher { get; private set; }
    }
}